

namespace Stee.CAP8.MessageBus.Interface.Factories
{
    using System;
    using System.Collections.Generic;
    using System.Text;
    using Stee.CAP8.MessageBus.Interface.Configurations;

    /*
     * Kafka consumer uses polling to 'listen' to messages, therefore is not automatically made know to new messages.
     * Using a polling method, the consumer has a while loop to constantly poll for new messages (never ending).
     * On subscription, a polling thread has to be created and maintained preferrably by the subscriber themselves.
     * Required information: Topic, notification handler
     *
     * IFactory
     *     - KafkaFactory
     *     - RabbitMQFactory
     */
    public static class SubscriberFactory<T>
    {
        static SubscriberFactory()
        {
            subscriberConfiguration = new SubscriberConfiguration();

            //// Get consumer configuration



            //// Create configuration
            //// Use connection properties here
            //// https://docs.confluent.io/current/installation/configuration/consumer-configs.html
            //// TODO: Build configuration reader
            this.consumerConfig = new ConsumerConfig
            {
                BootstrapServers = "127.0.0.1:9092", // Mandatory config
                GroupId = this.GroupID, // Mandatory config
                ClientId = this.ClientID,
                AutoOffsetReset = AutoOffsetReset.Earliest,
                EnableAutoCommit = true,
                EnableAutoOffsetStore = true,
                MaxPollIntervalMs = 300000,
                SessionTimeoutMs = 10000,
            };
        }



        /// <summary>
        /// Create new subscriber
        /// </summary>
        /// <returns></returns>
        public static ISubscriber<T> CreateSubscriber()
        {
            try
            {
                ISubscriber subscriber = new SubscriberImpl();



                return subscriber;
            }
            catch (Exception)
            {
                throw;
            }
        }
    }
}
